package co.gov.medellin.ssti.sub.service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

import javax.naming.NamingException;

import co.gov.medellin.ssti.sub.common.ConexionFactory;
import co.gov.medellin.ssti.sub.model.dao.DAOFactory;
import co.gov.medellin.ssti.sub.model.dao.ISubprogramaDAO;
import co.gov.medellin.ssti.sub.model.dao.exception.DAOException;
import co.gov.medellin.ssti.sub.model.vo.AtributoVO;
import co.gov.medellin.ssti.sub.model.vo.SubprogramaVO;
import co.gov.medellin.ssti.sub.web.form.SubprogramaForm;

public class SubprogramaService {

	/**
	 * 
	 * @param codeUser
	 * @param userGroupName
	 * @param codeprograma
	 * @param codeArea
	 * @return
	 * @throws DAOException
	 */
	public Collection<SubprogramaVO> findSubprogramaUser(Long codeUser,
			String userGroupName, Long codeprograma, Long codeArea)
			throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;
		SubprogramaVO subProgramaVO = new SubprogramaVO();
		subProgramaVO.setCodePrograma(codeprograma);
		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.findSubprograma(subProgramaVO, codeUser,
					userGroupName, codeArea);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @return
	 */
	public List<SubprogramaVO> loadAllSubprogramas() throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.loadAllSubprogramas();
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param programaCode
	 * @return
	 * @throws DAOException
	 */
	public List<SubprogramaVO> loadAllSubprogramasByPrograma(String programaCode)
			throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.loadAllSubprogramasByPrograma(programaCode);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param codeSubprograma
	 * @return
	 * @throws DAOException
	 */
	public AtributoVO getGestor(String codeSubprograma) throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.getGestor(codeSubprograma);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param criteria
	 * @return
	 * @throws DAOException
	 */
	public Collection<SubprogramaVO> findSubprogramaByCriteria(
			SubprogramaVO criteria) throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.findSubprogramaByCriteria(criteria);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param criteria
	 * @return
	 * @throws DAOException
	 */
	public Collection<SubprogramaVO> findInformacionSubprogramaByCriteria(
			SubprogramaVO criteria) throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO
					.findInformacionSubprogramaByCriteria(criteria);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param criteria
	 * @param codeUser
	 * @param groupUserName
	 * @param areaUser
	 * @return
	 * @throws DAOException
	 */
	public Collection<SubprogramaVO> findSubprogramaByCriteria(
			SubprogramaVO criteria, Long codeUser, String groupUserName,
			Long areaUser) throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.findSubprogramaByCriteria(criteria, codeUser,
					groupUserName, areaUser);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param criteria
	 * @param codeUser
	 * @param groupUserName
	 * @param areaUser
	 * @return
	 * @throws DAOException
	 */
	public Collection<SubprogramaVO> findAllowedSubprogramaWithGestorByCriteria(
			SubprogramaVO criteria, Long codeUser, String groupUserName,
			Long areaUser) throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.findAllowedSubprogramaWithGestorByCriteria(
					criteria, codeUser, groupUserName, areaUser);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param criteria
	 * @param codeUser
	 * @param groupUserName
	 * @param areaUser
	 * @return
	 * @throws DAOException
	 */
	public Collection<SubprogramaVO> findSubprograma(SubprogramaVO criteria,
			Long codeUser, String groupUserName, Long areaUser)
			throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.findSubprograma(criteria, codeUser,
					groupUserName, areaUser);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param criteria
	 * @param codeUser
	 * @param groupUserName
	 * @param areaUser
	 * @return
	 * @throws DAOException
	 */
	public Collection<SubprogramaVO> findAllowedSubprograma(
			SubprogramaVO criteria, Long codeUser, String groupUserName,
			Long areaUser) throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.findAllowedSubprograma(criteria, codeUser,
					groupUserName, areaUser);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * RESPONS: BENEFICIODAO
	 * 
	 * @param strArr
	 * @param i
	 * @param fechaBeneficio
	 * @return
	 * @throws DAOException
	 */
	public int insertBeneficioOtorgado(String strArr[], int i,
			String fechaBeneficio) throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.insertBeneficioOtorgado(strArr, i,
					fechaBeneficio);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}
	
	public int insertBeneficioOtorgadoEmpresa(String strArr[], int i,
			String fechaBeneficio) throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.insertBeneficioOtorgadoEmpresa(strArr, i,
					fechaBeneficio);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * RESP: BENEFICIODAO.
	 * 
	 * @param strArr
	 * @param i
	 * @param DateBenefit
	 * @param codeBot
	 * @return
	 * @throws DAOException
	 */
	public int updateBeneficioOtorgado(String strArr[], int i,
			String DateBenefit, String codeBot) throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.updateBeneficioOtorgado(strArr, i,
					DateBenefit, codeBot);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * RESP. BENEFICIODAO.
	 * 
	 * @param strArr
	 * @param i
	 * @param DateBenefit
	 * @param codeBot
	 * @param tipoBot
	 * @return
	 * @throws SQLException
	 */
	public int updateBeneficioOtorgado(String strArr[], int i,
			String DateBenefit, String codeBot, String tipoBot)
			throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.updateBeneficioOtorgado(strArr, i,
					DateBenefit, codeBot, tipoBot);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param codeSubpro
	 * @return
	 * @throws DAOException
	 */
	public SubprogramaVO findPropiedadesSubprograma(long codeSubpro)
			throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.findPropiedadesSubprograma(codeSubpro);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * RESP: BENEFICIODAO.
	 * 
	 * @return
	 * @throws DAOException
	 */
	public String findCodMaxBenOtor() throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.findCodMaxBenOtor();
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * NOT EVEN USED. RESP. BENEFICIODAO.
	 * 
	 * @return
	 * @throws DAOException
	 */
	public String findCantidadDisponible() throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.findCantidadDisponible();
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @return
	 * @throws DAOException
	 */
	public String findMaxCodigo() throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.findMaxCodigo();
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * FORM EN DAO???
	 * 
	 * @param subform
	 * @param user
	 * @param strTerminal
	 * @param strDate
	 * @return
	 * @throws SQLException
	 */
	public int insertBeneficio(SubprogramaForm subform, String user,
			String strTerminal, String strDate) throws SQLException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.insertBeneficio(subform, user, strTerminal,
					strDate);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param codigo
	 * @return
	 * @throws DAOException
	 */
	public boolean findEstadoSubprogramaByCodigo(long codigo)
			throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.findEstadoSubprogramaByCodigo(codigo);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * ...
	 * 
	 * @param codePrograma
	 * @return
	 * @throws DAOException
	 */
	public Collection<SubprogramaVO> findActivarSubprogramas(long codePrograma)
			throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.findActivarSubprogramas(codePrograma);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param codeUser
	 * @param groupUserName
	 * @param areaUser
	 * @return
	 * @throws DAOException
	 */
	public Collection<SubprogramaVO> findActivarSubprogramas(Long codeUser,
			String groupUserName, Long areaUser) throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.findActivarSubprogramas(codeUser,
					groupUserName, areaUser);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param criteria
	 * @param codeUser
	 * @param groupUserName
	 * @param areaUser
	 * @return
	 * @throws DAOException
	 */
	public Collection<SubprogramaVO> findSubprogramasVigentes(
			SubprogramaVO criteria, Long codeUser, String groupUserName,
			Long areaUser) throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.findSubprogramasVigentes(criteria, codeUser,
					groupUserName, areaUser);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param codeSub
	 * @return
	 * @throws DAOException
	 */
	public String findNombreByCodigo(long codeSub) throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.findNombreByCodigo(codeSub);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param codeBOT
	 * @return
	 * @throws DAOException
	 */
	public String findCodigoSubprogramaByCodigoBOT(long codeBOT)
			throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.findCodigoSubprogramaByCodigoBOT(codeBOT);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param codeSub
	 * @return
	 * @throws DAOException
	 */
	public boolean isRelacionadoConSede(long codeSub) throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.isRelacionadoConSede(codeSub);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * 
	 * @param codeSubprograma
	 * @return
	 * @throws DAOException
	 */
	public String findCodigoProgramaByCodigoSubprograma(long codeSubprograma)
			throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO
					.findCodigoProgramaByCodigoSubprograma(codeSubprograma);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

	/**
	 * Metodo que consulta en TCS_BEN_SUBPROGRAMA el subprograma con codigo =
	 * codeSubprograma y grupo_familiar = 'S' para determinar si el beneficio es
	 * para un grupo familiar.
	 * 
	 * @param codeSubprograma
	 * @return
	 * @throws SQLException
	 */
	public boolean isSubprogramaParaGrupoFamiliar(Long codeSubprograma)
			throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO
					.isSubprogramaParaGrupoFamiliar(codeSubprograma);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}
	
	public SubprogramaVO findSubprogramaByCodigo(Long codeSubprograma)
			throws DAOException {
		ISubprogramaDAO subprogramaDAO = null;

		try {
			Connection con = ConexionFactory.getInstance().getConnection();
			subprogramaDAO = DAOFactory.getDAOFactory(DAOFactory.ORACLE)
					.getSubprogramaDAO(con);
			return subprogramaDAO.findSubprogramaByCodigo(codeSubprograma);
		} catch (NamingException e) {
			throw new DAOException(e);
		} catch (SQLException e) {
			throw new DAOException(e);
		} finally {
			if (subprogramaDAO != null) {
				if (!subprogramaDAO.isConnClosed()) {
					subprogramaDAO.close();
				}
			}
		}
	}

}
